package com.huatech.common;

/**
 * 
 * @author lihua_java@163.com
 *
 */
public enum CodeEnum {
    CODE_OK(0, "成功"),
    CODE_FAIL(1, "失败"),
    CODE_TOKEN_EXPIRED(100001, "票据过期"),
    CODE_NO_DATA(100204, "没有数据"),
    CODE_REPEAT_REQUEST(100205, "重复请求"),
    CODE_PARAM_ERROR(100400, "请求参数非法"),
    CODE_FREQUENCY_LIMIT(100410, "频率限制"),
    CODE_AUTH_FAIL(100401, "客户端认证失败"),
    CODE_SYSTEM_ERROR(100500, "系统内部错误"),
    ;

    private int code;
    private String msg;

    CodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public static CodeEnum codeOf(int code) {
        for (CodeEnum state : values()) {
            if (state.getCode() == code) {
                return state;
            }
        }
        return CodeEnum.CODE_OK;
    }
}
